package trainfengxing.controller;

import org.springframework.web.bind.annotation.*;
import trainfengxing.pojo.Result;
import trainfengxing.pojo.train;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import trainfengxing.pojo.user;

import java.util.List;

/**
 * 火车管理Controller
 */
@Slf4j
@RestController
public class trainController {
    @Autowired
    private trainfengxing.service.trainService trainService;
    //查询所有的车票信息
    @GetMapping("/seat")
    public Result seat(){
        log.info("查询所有的车票信息");
       List<train> trains =  trainService.seat();
        return Result.success(trains);
    }

    @GetMapping("/user")
    public Result userlogin(){
        log.info("用户的登录操作");
        List<user> users = trainService.userlogin();
        return Result.success(users);
    }

//    条件查询车次
      @PostMapping ("/selecttrain")
    public Result selecttrain(@RequestBody train train){
        log.info("新购买的订单：{}", train);
//        调用servive
         List<train> trains = trainService.selecttrain(train);
         return Result.success(trains);
     }


     @DeleteMapping("/deletetrain")
    public Result delectetrain(@RequestBody train train){
        log.info("删除车次信息：{}", train);
        trainService.deletetrain(train);
        return Result.success();
    }


    @PostMapping("/updatetrain")
    public Result updatetrain(@RequestBody train train){
        log.info("修改车次信息：{}", train);
        trainService.updatetrain(train);
        return Result.success();
    }
}